<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <input type="button" id="btn1" value="get请求">
    <input type="button" id="btn2" value="post请求">
    <input type="button" id="btn3" value="jsonp请求">
    <input type="button" id="btn4" value="jsonp的超时请求">
    <input type="button" id="btn5" value="ajax的超时请求">
</body>
<script src="request.js"></script>
<script>
    const obtn1 = document.getElementById("btn1")
    const obtn2 = document.getElementById("btn2")
    const obtn3 = document.getElementById("btn3")
    const obtn4 = document.getElementById("btn4")
    const obtn5 = document.getElementById("btn5")

    obtn1.onclick = function(){
        request({
            url:"http://localhost:3000/api",
            data:{
                type:"login"
            },
            success:res=>{
                console.log(res)
            }
        })
    }

    obtn2.onclick = function(){
        request({
            type:"post",
            url:"http://localhost:3000/api",
            data:{
                type:"register"
            },
            success:res=>{
                console.log(res)
            }
        })
    }

    obtn3.onclick = function(){
        request({
            type:"jsonp",
            url:"http://localhost:3000/api",
            data:{
                type:"jsonp3",
                callback:"ajhsgfaf"
            },
            jsonp:"callback",
            success:res=>{
                console.log(res)
            }
        })
    }

    obtn4.onclick = function(){
        request({
            type:"jsonp",
            url:"http://localhost:3000/api",
            data:{
                type:"jsonp3",
                callback:"ajhsgfaf"
            },
            jsonp:"callback",
            success:res=>{
                console.log(res);
            },
            error:code=>{
                console.log(code);
            },
            timeout: 10
        })
    }

    obtn5.onclick = function(){
        request({
            url:"http://localhost:3000/api",
            data:{
                type:"login"
            },
            success:res=>{
                console.log(res)
            },
            error:code=>{
                console.log(code);
            },
            timeout: 10
        })
    }
</script>
</html>